// ml:run = $bin < input
#include <iostream>
#include <vector>
#include <cctype>
#include <string>
#include <map>

std::vector<std::string> v
{
    "zero",
    "one",
    "two",
    "three",
    "four",
    "five",
    "six",
    "seven",
    "eight",
    "nine",
    "ten",
    "eleven",
    "twelve",
    "thirteen",
    "fourteen",
    "fifteen",
    "sixteen",
    "seventeen",
    "eighteen",
    "nineteen",
    "twenty",
    "twenty-one",
    "twenty-two",
    "twenty-three",
    "twenty-four",
    "twenty-five",
    "twenty-six",
    "twenty-seven",
    "twenty-eight",
    "twenty-nine",
    "thirty",
    "thirty-one",
    "thirty-two",
    "thirty-three",
    "thirty-four",
    "thirty-five",
    "thirty-six",
    "thirty-seven",
    "thirty-eight",
    "thirty-nine",
    "forty",
    "forty-one",
    "forty-two",
    "forty-three",
    "forty-four",
    "forty-five",
    "forty-six",
    "forty-seven",
    "forty-eight",
    "forty-nine",
    "fifty",
    "fifty-one",
    "fifty-two",
    "fifty-three",
    "fifty-four",
    "fifty-five",
    "fifty-six",
    "fifty-seven",
    "fifty-eight",
    "fifty-nine",
    "sixty",
    "sixty-one",
    "sixty-two",
    "sixty-three",
    "sixty-four",
    "sixty-five",
    "sixty-six",
    "sixty-seven",
    "sixty-eight",
    "sixty-nine",
    "seventy",
    "seventy-one",
    "seventy-two",
    "seventy-three",
    "seventy-four",
    "seventy-five",
    "seventy-six",
    "seventy-seven",
    "seventy-eight",
    "seventy-nine",
    "eighty",
    "eighty-one",
    "eighty-two",
    "eighty-three",
    "eighty-four",
    "eighty-five",
    "eighty-six",
    "eighty-seven",
    "eighty-eight",
    "eighty-nine",
    "ninety",
    "ninety-one",
    "ninety-two",
    "ninety-three",
    "ninety-four",
    "ninety-five",
    "ninety-six",
    "ninety-seven",
    "ninety-eight",
    "ninety-nine",
};

int hun = 7;

int count[2000];

int calc(std::string const& a)
{
    int ret = 0;
    for (auto ch : a)
        ret += bool(std::isalpha(ch));
    return ret;
}

void init()
{
    for (int i = 1; i <= 99; i++) {
        count[i] = calc(v[i]);
    }
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    init();
    int T; std::cin >> T;
    while (T--) {
        int n; std::cin >> n;
        bool thu = n == 1000;
        if (n == 1000) n--;
        int ans = 0;
        for (int j = 1; j <= std::min(99, n); j++)
            ans += count[j];
        int t = n / 100;
        for (int i = 1; i <= t; i++) {
            ans += count[i] + hun;
            for (int j = 100 * i + 1; j <= std::min(100 * (i + 1) - 1, n); j++) {
                int tj = j - 100 * i;
                ans += count[i] + hun + 3 + count[tj];
            }
        }
        if (thu) ans += 11;
        std::cout << ans << "\n";
    }
}

